package game.leon.seawar;

import clojure.lang.RT;
import game.leon.seawar.server.Server;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.StopWatch;

import java.io.IOException;

/**
 * User: bianpeng
 * Date: 11-12-28
 * 试验项目
 * 游戏名称: 海王争霸
 * 试验一下那个leon引擎, 现在看起来已经很不错了, 应该用于大点的项目测试一下
 */
public class SeaWarMain {
    public static void main(String[] args) {
        Logger logger = Logger.getLogger(SeaWarMain.class);
        // game server
        ApplicationContext context = new ClassPathXmlApplicationContext(
                new String[]{"application-context.xml"});
        StopWatch watch = new StopWatch();
        Server server = context.getBean(Server.class);
        try {
            watch.start();
            server.start();
            watch.stop();
            logger.info(String.format("server start in %d ms", watch.getLastTaskTimeMillis()));
        } catch (IOException e) {
            logger.error("server start failed", e);
        }
        // clojure
        try {
            watch.start();
            RT.loadResourceScript("seawar/battle.clj");
            watch.stop();
            logger.info(String.format("clj cold start in %d ms", watch.getLastTaskTimeMillis()));
        } catch (IOException e) {
            logger.error("scripts failed", e);
        }
        game.leon.hello.greet();
    }
}
